package com.example.basic.reflects;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

public class PackageClassReflectExample {

    /**
     * 包私有的类是否可以反射的测试
     * @param args
     */
    public static void main(String[] args) {
        try {
            Class cls = Class.forName("com.example.basic.proxy.TestProxy");
            Constructor[] constructors = cls.getDeclaredConstructors();
            System.out.println(constructors.length);
            constructors[0].setAccessible(true);
            Object o1 = constructors[0].newInstance();
            System.out.println(o1.getClass().getName());
        } catch (ClassNotFoundException e) {
            System.out.println(e.getMessage());
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            System.out.println(e.getMessage());
            e.printStackTrace();
        } catch (InstantiationException e) {
            System.out.println(e.getMessage());
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            System.out.println(e.getMessage());
            e.printStackTrace();
        }
    }

}
